package com.telecomyt.jwportal.widget;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;

/**
 * @author created by chengDa
 * @time 2020/10/13  11:38
 * @description
 */
public class GlideImageLoader {
    /**
     * 配置加载
     */
    public static void load(Context mContext, String path, Drawable var2, Drawable var3, Drawable var4, ImageView mImageView, ErrorListener listener) {
//        Luban.with(mContext)
//                .load(path)                                   // 传人要压缩的图片列表
//                .ignoreBy(100)                                  // 忽略不压缩图片的大小
//                .setTargetDir(getPath())                        // 设置压缩后文件存储位置
//                .setCompressListener(new OnCompressListener() { //设置回调
//                    @Override
//                    public void onStart() {
//                    }
//
//                    @Override
//                    public void onSuccess(File file) {
//                        String absolutePath = file.getAbsolutePath();
//
//                    }
//
//                    @Override
//                    public void onError(Throwable e) {
//                    }
//                }).launch();    //启动压缩
        Glide.with(mContext)
                .load(path)
                .placeholder(var2)
                .error(var3)
                .fallback(var4)
                .transform(new GlideCircleTransform())//图片圆形
                .listener(new RequestListener<Drawable>() {
                    @Override
                    public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
                        listener.error();
                        return true;
                    }

                    @Override
                    public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
                        return false;
                    }
                })
                .into(mImageView);
    }


    public interface ErrorListener {
        void error();

    }


}
